Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LLMM1 kernel #28

Merged
merged 5 commits into from
Jun 14, 2024
Merged

Fix LLMM1 kernel #28

merged 5 commits into from
Jun 14, 2024

Conversation

fxmarty
Copy link

@fxmarty fxmarty commented May 31, 2024

As per title.

The kernel is broken and yields wrong generation, for example with TP=2 & llama 2 7B. There are two main issues in the kernel:

  • Number of thread in a block is not a multiple of the warp size, although we use warp shuffle operations.
  • Indexing on the block of rows is wrong & indexing to load the weight matrix is wrong.

Example repro:

import torch
from transformers import AutoModelForCausalLM
# from gemv_ext import LLMM1
from vllm import _custom_C

m = 4096
n = 1

for k in range(200, 1600, 8):
    with torch.no_grad():

        down_proj_weight = torch.rand(m, k, device="cuda", dtype=torch.float16)
        inp = torch.rand(n, k, device="cuda", dtype=torch.float16) - 0.5

        out_functional = torch.nn.functional.linear(inp, down_proj_weight)

        out_custom = torch.empty(n, m, dtype=inp.dtype, device="cuda")
        _custom_C.LLMM1(down_proj_weight, inp, out_custom, 4)

        absdiff = (out_functional.to(torch.float32) - out_custom.to(torch.float32)).abs()

        print("------ k:", k)
        print("  % off:", absdiff.mean().item() / out_functional.abs().mean().item())

Copy link

@dllehr-amd dllehr-amd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fxmarty I appreciate the PR! We were mainly focused on TP=8 and TP=1. These changes look good to me.

@fxmarty
Copy link
Author

fxmarty commented Jun 12, 2024

Thank you, I fixed the linting conflict.

@shajrawi
Copy link
Collaborator

Still have failing CI

Run codespell --toml pyproject.toml
./csrc/custom/custom_kernels.cu:88: accross ==> across
Error: Process completed with exit code 65.

@fxmarty
Copy link
Author

fxmarty commented Jun 14, 2024

@shajrawi thank you, should be fixed

@shajrawi shajrawi merged commit d3da246 into ROCm:main Jun 14, 2024
@shajrawi
Copy link
Collaborator

Merged! Thanks for the fix!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants